package com.dhcc.sdc.cdss.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.cdss.entity.SdcCdssExamMatchEntity;
import com.dhcc.sdc.cdss.service.ISdcCdssExamMatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 *
 *
 * @ClassName: SdcCdssExamMatchController
 * @Description: TODO
 * @author zhangdc
 * @date 2022-06-23 14:46:12
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdccdssexammatch")
public class SdcCdssExamMatchController {

    private String PREFIX = "/backend/sds/sdccdssexammatch/";

    @Autowired
    private ISdcCdssExamMatchService sdcCdssExamMatchService;

    /**
     * 获取列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
        Page<SdcCdssExamMatchEntity> page = new PageFactory<SdcCdssExamMatchEntity>().defaultPage();
        List<SdcCdssExamMatchEntity> result = this.sdcCdssExamMatchService.page(page,params);
        page.setRecords((List<SdcCdssExamMatchEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcCdssExamMatchEntity sdcCdssExamMatch) {
        if (CommonUtil.isOneEmpty(sdcCdssExamMatch)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdcCdssExamMatch.insert();
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdcCdssExamMatchId) {

        this.sdcCdssExamMatchService.deleteById(sdcCdssExamMatchId);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcCdssExamMatchEntity sdcCdssExamMatch) {
        if (CommonUtil.isOneEmpty(sdcCdssExamMatch)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdcCdssExamMatchEntity old = this.sdcCdssExamMatchService.selectById(sdcCdssExamMatch.getId());

        old.setItemId(sdcCdssExamMatch.getItemId());
        old.setOrderId(sdcCdssExamMatch.getOrderId());
        old.updateAllColumnById();
        return R.ok();
    }
}
